const TransformPages = require('uni-read-pages')
const { webpack } = new TransformPages()
module.exports = {
  chainWebpack: config => {
    if (process.env.NODE_ENV === 'development') {
      config.module
        .rule('eslint')
        .use('eslint-loader')
        .loader('eslint-loader')
        .tap(options => {
          options.fix = true
          return options
        })
        .end()
    }
  },
  transpileDependencies: ['uview-ui'],
  configureWebpack: {
    plugins: [
      new webpack.DefinePlugin({
        ROUTES: webpack.DefinePlugin.runtimeValue(() => {
          const tfPages = new TransformPages({
            includes: ['path', 'name', 'aliasPath']
          })
          return JSON.stringify(tfPages.routes)
        }, true)
      })
    ]
  }
}
